var Tools = function() {

    var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);


    var UrlEvent = function() {
        //解析Url中的参数
        var GetUrlParams = function(url) {

            var _UrlParams = {};
            var _UrlSub = url.split('?');
            if (_UrlSub[1] && _UrlSub[1] != "") {
                _UrlSub[1] += "&";
                var _Params = _UrlSub[1].split('&');
                for (var i in _Params) {
                    if (_Params[i] != "") {
                        var _param = _Params[i].split('=');
                        _UrlParams[_param[0]] = decodeURIComponent(_param[1]);
                    }
                }
            }

            return _UrlParams;
        };

        var GetUrl = function(Url, ParamName, ParamValue) {

            var UrlParams = GetUrlParams(Url);
            if (Url.indexOf("?") > -1) {
                delete UrlParams[ParamName];
                var _UrlSub = Url.split('?');
                var NewUrl = _UrlSub[0] + "?";
                for (var i in UrlParams) {
                    NewUrl += i + "=" + encodeURI(UrlParams[i]) + "&";
                }
                Url = NewUrl + ParamName + "=" + ParamValue;
            } else {
                Url = Url + "?" + ParamName + "=" + ParamValue;

            }

            return Url;

        };

        return {
            GetUrlParams: GetUrlParams,
            GetUrl: GetUrl
        }
    }();

    //格式化为桩号
    var GetStakeNo = function(str) {
        var StakeNo = "K" + str;
        StakeNo = StakeNo.replace(".", "+");
        var P_Location_s_s = StakeNo.split('+');
        if (P_Location_s_s[1]) {
            StakeNo = P_Location_s_s[0] + "+" + P_Location_s_s[1];
            if (P_Location_s_s[1].length == 2) {
                StakeNo = StakeNo + "0";
            }
            if (P_Location_s_s[1].length == 1) {
                StakeNo = StakeNo + "00";
            }
        }
        return StakeNo;
    }

    var offset = function(el) {
        var sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        var st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);

        var rect = el.getBoundingClientRect();
        return {
            l: rect.left + sl,
            t: rect.top + st,
            w: el.offsetWidth,
            h: el.offsetHeight
        };
    };
    var IsAndroid = function() {
            var u = navigator.userAgent;
            var isAndroid = (/android/i).test(u);
            //alert(isAndroid+'是安卓')
            return isAndroid;
        }
        /**
         * 版本比较 如果新版本比老版本大 返回true
         */
    var CheckVer = function(oldVer, newVer) {
        var OldVerSub = oldVer.split('.');
        var NewVerSub = newVer.split('.');
        if (Number(OldVerSub[0]) < Number(NewVerSub[0])) {
            return true;
        } else {
            if (Number(OldVerSub[1]) < Number(NewVerSub[1])) {
                return true;
            } else {
                if (Number(OldVerSub[2]) < Number(NewVerSub[2])) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 返回GUID
     *  uuid(8, 16) // "098F4D35"
     *  uuid(8, 10) // "47473046"
     *  uuid(8, 2)  //  "01001010"
     * @param {Object} len
     * @param {Object} radix
     */
    var uuid = function(len, radix) {
            var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
            var uuid = [],
                i;
            radix = radix || chars.length;

            if (len) {
                // Compact form
                for (i = 0; i < len; i++)
                    uuid[i] = chars[0 | Math.random() * radix];
            } else {
                // rfc4122, version 4 form
                var r;

                // rfc4122 requires these characters
                uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
                uuid[14] = '4';

                // Fill in random data.  At i==19 set the high bits of clock sequence as
                // per rfc4122, sec. 4.1.5
                for (i = 0; i < 36; i++) {
                    if (!uuid[i]) {
                        r = 0 | Math.random() * 16;
                        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                    }
                }
            }

            return uuid.join('');
        }
        //获取Url中的参数
    var GetUrlParams = function(UrlStr) {
        var _UrlParams = {};
        var _UrlSub = UrlStr.split('?');
        if (_UrlSub[1] && _UrlSub[1] != "") {
            _UrlSub[1] += "&";
            var _Params = _UrlSub[1].split('&');
            for (var i in _Params) {
                if (_Params[i] != "") {
                    var _param = _Params[i].split('=');
                    _UrlParams[_param[0]] = _param[1];
                }
            }
        }

        return _UrlParams;
    }
    var LoadScript = function(src, callback, charset) {
            var script = document.createElement('script');
            script.setAttribute('language', 'javascript');
            if (charset) {
                script.setAttribute('charset', charset);
            }
            script.setAttribute('type', 'text/javascript');
            // script.setAttribute('defer', '');
            script.setAttribute('src', src);
            document.getElementsByTagName("head")[0].appendChild(script);

            if (document.all) {
                script.onreadystatechange = function() {
                    if (this.readyState == 4 || this.readyState == 'complete' || this.readyState == 'loaded') {
                        if (callback) {
                            callback();
                        }
                    }
                };
            } else {
                script.onload = function() {
                    if (callback) {
                        callback();
                    }
                };
            }
        }
        //获取时间戳
    var GetTimestamp = function(DateTime) {
        return Math.round(DateTime.getTime() / 1000);
    }
    var GetDateTimeByTimestamp = function(Timestamp) {
        var UTCTime = new Date(Timestamp * 1000);
        var RealTime = UTCTime.getFullYear() + "-" + (UTCTime.getMonth() + 1) + "-" + UTCTime.getDate() + " " + UTCTime.getHours() + ":" + UTCTime.getMinutes() + ":" + UTCTime.getSeconds();
        return RealTime;
    }
    var dateDiff = function(date1, date2) {
        var type1 = typeof date1,
            type2 = typeof date2;
        if (type1 == 'string')
            date1 = Func.stringToTime(date1);
        else if (date1.getTime)
            date1 = date1.getTime();
        if (type2 == 'string')
            date2 = Func.stringToTime(date2);
        else if (date2.getTime)
            date2 = date2.getTime();
        return (date1 - date2) / 1000;
        //结果是秒
    }
    var DateToFullDateTimeString = function(date) {

        var year = date.getFullYear();
        var month = date.getMonth();
        var day = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();

        var datestr;

        if (month < 9) {
            month = '0' + (month + 1);
        }
        if (day < 10) {
            day = '0' + day;
        }
        if (hour < 10) {
            hour = '0' + hour;
        }
        if (minute < 10) {
            minute = '0' + minute;
        }
        if (second < 10) {
            second = '0' + second;
        }

        datestr = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
        return datestr;
    }
    var DateToShortDateTimeString = function(date) {

        var type1 = typeof date;
        if (type1 == 'string')
            date = Func.stringToDate(date);
        var year = date.getFullYear();
        var month = date.getMonth();
        var day = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();

        var datestr;

        if (month < 9) {
            month = '0' + (month + 1);
        }
        if (day < 10) {
            day = '0' + day;
        }
        if (hour < 10) {
            hour = '0' + hour;
        }
        if (minute < 10) {
            minute = '0' + minute;
        }
        if (second < 10) {
            second = '0' + second;
        }

        datestr = month + '-' + day + ' ' + hour + ':' + minute;
        return datestr;
    }
    var DateToTimeString = function(date) {

            var type1 = typeof date;
            if (type1 == 'string')
                date = Func.stringToDate(date);
            var year = date.getFullYear();
            var month = date.getMonth();
            var day = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();

            var datestr;

            if (month < 9) {
                month = '0' + (month + 1);
            }
            if (day < 10) {
                day = '0' + day;
            }
            if (hour < 10) {
                hour = '0' + hour;
            }
            if (minute < 10) {
                minute = '0' + minute;
            }
            if (second < 10) {
                second = '0' + second;
            }

            datestr = hour + ':' + minute;
            return datestr;
        }
        //简化时间
    var FormatDate = function(time) {
        var now = new Date();
        var SpanS = parseInt(Func.dateDiff(now, time));
        var SpanM = parseInt(SpanS / 60);
        //分钟
        if (SpanM < 60) {
            return SpanM + "分钟前";
        }
        var SpanH = parseInt(SpanM / 60);
        if (SpanH < 24) {
            return SpanH + "小时前";
        }
        var SpanD = parseInt(SpanH / 24);
        if (SpanD < 14) {
            return SpanD + "天前";
        }

        var SpanW = parseInt(SpanD / 7);
        if (SpanW < 4) {
            return SpanW + "周前";
        }
        return Func.DateToShortDateTimeString(time);
    }


    //转换Json中的日期类型
    var GetJsonDate = function(time) {
            if (time != null) {
                var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10));
                // var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                //var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                //return date.getFullYear() + "-" + month + "-" + currentDate;
                return date;
            }
            return "";
        }
        //转换Json中的日期类型
    var GetJsonDateStr = function(time) {
            if (time != null) {
                var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10));
                // var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                //var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                //return date.getFullYear() + "-" + month + "-" + currentDate;
                return Func.DateToFullDateTimeString(date);
            }
            return "";
        }
        //预加载图片
    var PreloadImages = function(arr) {
            var newimages = [],
                loadedimages = 0
            var postaction = function() {} //此处增加了一个postaction函数
            var arr = (typeof arr != "object") ? [arr] : arr

            function imageloadpost() {
                loadedimages++
                if (loadedimages == arr.length) {
                    postaction(newimages) //加载完成用我们调用postaction函数并将newimages数组做为参数传递进去
                }
            }

            for (var i = 0; i < arr.length; i++) {
                newimages[i] = new Image()
                newimages[i].src = arr[i]
                newimages[i].onload = function() {
                    imageloadpost()
                }
                newimages[i].onerror = function() {
                    imageloadpost()
                }
            }
            return { //此处返回一个空白对象的done方法
                done: function(f) {
                    postaction = f || postaction
                }
            }
        }
        //加载图片后替换Src属性
    var loadImage = function(Obj, url) {
        var img = new Image();
        //创建一个Image对象，实现图片的预下载
        img.src = url;
        if (img.complete) { // 如果图片已经存在于浏览器缓存，直接调用回调函数
            Obj.attr("src", url);
            return;
            // 直接返回，不用再处理onload事件
        }
        img.onload = function() { //图片下载完毕时异步调用callback函数。
            //callback.call(img); //将回调函数的this替换为Image对象
            Obj.attr("src", url);
        };
    }
    var imageReady = (function() {
        var list = [],
            timer = null,
            prop = [
                ['width', 'height'],
                ['naturalWidth', 'naturalHeight']
            ],
            natural = Number(typeof document.createElement('img').naturalHeight === 'number'), //是否支持HTML5新增的 naturalHeight
            tick = function() {
                for (var i = 0; i < list.length; i++) {
                    list[i].end ? list.splice(i--, 1) : check.call(list[i], null);
                }
                list.length && (timer = setTimeout(tick, 50)) || (timer = null);
            },
            /** overflow: 检测图片尺寸的改变
             *  img.__width,img.__height: 初载入时的尺寸
             */
            check = function() {
                if (this[prop[natural][0]] !== this.__width || this[prop[natural][1]] !== this.__height || this[prop[natural][0]] * this[prop[natural][1]] > 1024) {
                    this.onready.call(this, null);
                    this.end = true;
                }
            };
        return function(_img, onready, onload, onerror) {
            onready = onready || new Function();
            onload = onload || new Function();
            onerror = onerror || new Function();
            var img = typeof _img == 'string' ? new Image() : _img;
            img.onerror = function() { // ie && ie<=8 的浏览器必须在src赋予前定义onerror
                onerror.call(img, null);
                img.end = true;
                img = img.onload = img.onerror = img.onreadystatechange = null;
            }
            if (typeof _img == 'string')
                img.src = _img;
            if (!img)
                return;
            if (img.complete) {
                onready.call(img, null);
                onload.call(img, null);
                return;
            }
            img.__width = img[prop[natural][0]];
            img.__height = img[prop[natural][1]];
            img.onready = onready;
            check.call(img, null);
            img.onload = img.onreadystatechange = function() {
                if (img && img.readyState && img.readyState != 'loaded' && img.readyState != 'complete') {
                    return;
                }!img.end && check.call(img, null);
                onload.call(img, null);
                img = img.onload = img.onerror = img.onreadystatechange = null;
            }
            if (!img.end) {
                list.push(img);
                if (timer === null)
                    timer = setTimeout(tick, 50);
            }
        }
    })()

    //四舍五入
    var ForDight = function(Dight, How) {
        Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
        return Dight;
    }
    var CheckStr = function(str) {
        if (/[\'\"\\\<\>\&\$\*\+\=\%\?\#\^\(\)]/.test(str)) {
            return false;
        }
        return true;
    }
    var IsNum = function(str) {
        if (isNaN(str)) {
            return false;
        }
        return true;
    }
    var GetLen = function(str) {
            var unLen = str.replace(/[^\x00-\xff]/g, "**").length;
            return unLen;
        }
        //删除左右两端的空格
    var trim = function(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
    var CheckEmail = function(str) {
        var reEml = /^[\w\-\.]+@[a-z0-9]+(\-[a-z0-9]+)?(\.[a-z0-9]+(\-[a-z0-9]+)?)*\.[a-z]{2,4}$/i;
        var isOk = reEml.test(str);
        if (isOk == false) {
            return false;
        }
        return true;
    }
    var FillErrorView = function(TargetDivID, CallBack) {
        var html = '<div class="network-off"><div class="ico"></div><div><button class="btn btn-green" tapmode="btn-green-hov"><i class="icon-refresh"></i> 访问出错，请重试</button></div></div>';
        $("#" + TargetDivID).html(html);
        $("#" + TargetDivID).find("button").click(function() {
            $("#" + TargetDivID).html("");
            CallBack();
        });
        api.parseTapmode();

    }


    var ShowNoData = function(content, tagetDomId) {
        if (!content) content = "没有任何数据";
        var html = "<div class='noData ui-border-radius '><span>" + content + "</span></div>";
        $("#" + tagetDomId).html(html);
    }


    var FillLoadingView = function(TargetObj, style) {
        var html = "<div class='loader'><div class='loader-inner ball-beat loaderColor_blue'><div></div><div></div><div></div></div></div>";
        if (style) {
            switch (style) {
                case 0:
                    html = "<div class='loader'><div class='loader-inner ball-beat loaderColor_blue'><div></div><div></div><div></div></div></div>";
                    break;
                case 1:
                    html = "<div class='loader'><div class='loader-inner ball-clip-rotate'><div></div></div>";
                    break;
                case 2:
                    html = "<div class='loader'><div class='loader-inner ball-clip-rotate-pulse'><div></div><div></div></div>";
                    break;
                default:
                    break;

            }
        }

        TargetObj.append(html);
    }
    var RemoveLoading = function(TargetObj) {
        TargetObj.find(".loader").remove();
    }
    var FixLen = function(str, len) {
        if (str.length > len) {
            str = str.substring(0, len) + "...";
        }
        return str;
    }
    var HtmlEncode = function(str) {
        if (!str || str == "")
            return "";
        var div = document.createElement('div');
        div.appendChild(document.createTextNode(s));
        return div.innerHTML;
    }
    var HtmlDecode = function(str) {
        if (!str || str == "")
            return "";
        var _div = document.createElement('div');
        _div.innerHTML = str;
        return _div.innerText || div.textContent;
    }
    var base64decode = function(str) {
        var c1, c2, c3, c4;
        var i, len, out;

        len = str.length;
        i = 0;
        out = "";
        while (i < len) {
            /* c1 */
            do {
                c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
            } while (i < len && c1 == -1);
            if (c1 == -1)
                break;

            /* c2 */
            do {
                c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
            } while (i < len && c2 == -1);
            if (c2 == -1)
                break;

            out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

            /* c3 */
            do {
                c3 = str.charCodeAt(i++) & 0xff;
                if (c3 == 61)
                    return out;
                c3 = base64DecodeChars[c3];
            } while (i < len && c3 == -1);
            if (c3 == -1)
                break;

            out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

            /* c4 */
            do {
                c4 = str.charCodeAt(i++) & 0xff;
                if (c4 == 61)
                    return out;
                c4 = base64DecodeChars[c4];
            } while (i < len && c4 == -1);
            if (c4 == -1)
                break;
            out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
        }
        return out;
    }
    var base64encode = function(str) {
        var out, i, len;
        var c1, c2, c3;

        len = str.length;
        i = 0;
        out = "";
        while (i < len) {
            c1 = str.charCodeAt(i++) & 0xff;
            if (i == len) {
                out += base64EncodeChars.charAt(c1 >> 2);
                out += base64EncodeChars.charAt((c1 & 0x3) << 4);
                out += "==";
                break;
            }
            c2 = str.charCodeAt(i++);
            if (i == len) {
                out += base64EncodeChars.charAt(c1 >> 2);
                out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
                out += base64EncodeChars.charAt((c2 & 0xF) << 2);
                out += "=";
                break;
            }
            c3 = str.charCodeAt(i++);
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
            out += base64EncodeChars.charAt(c3 & 0x3F);
        }
        return out;
    }
    var SHA1 = function SHA1(msg) {

        function rotate_left(n, s) {
            var t4 = (n << s) | (n >>> (32 - s));
            return t4;
        };

        function lsb_hex(val) {
            var str = "";
            var i;
            var vh;
            var vl;

            for (i = 0; i <= 6; i += 2) {
                vh = (val >>> (i * 4 + 4)) & 0x0f;
                vl = (val >>> (i * 4)) & 0x0f;
                str += vh.toString(16) + vl.toString(16);
            }
            return str;
        };

        function cvt_hex(val) {
            var str = "";
            var i;
            var v;

            for (i = 7; i >= 0; i--) {
                v = (val >>> (i * 4)) & 0x0f;
                str += v.toString(16);
            }
            return str;
        };

        function Utf8Encode(string) {
            string = string.replace(/\r\n/g, "\n");
            var utftext = "";

            for (var n = 0; n < string.length; n++) {

                var c = string.charCodeAt(n);

                if (c < 128) {
                    utftext += String.fromCharCode(c);
                } else if ((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                } else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }

            }

            return utftext;
        };

        var blockstart;
        var i, j;
        var W = new Array(80);
        var H0 = 0x67452301;
        var H1 = 0xEFCDAB89;
        var H2 = 0x98BADCFE;
        var H3 = 0x10325476;
        var H4 = 0xC3D2E1F0;
        var A, B, C, D, E;
        var temp;

        msg = Utf8Encode(msg);

        var msg_len = msg.length;

        var word_array = new Array();
        for (i = 0; i < msg_len - 3; i += 4) {
            j = msg.charCodeAt(i) << 24 | msg.charCodeAt(i + 1) << 16 | msg.charCodeAt(i + 2) << 8 | msg.charCodeAt(i + 3);
            word_array.push(j);
        }

        switch (msg_len % 4) {
            case 0:
                i = 0x080000000;
                break;
            case 1:
                i = msg.charCodeAt(msg_len - 1) << 24 | 0x0800000;
                break;

            case 2:
                i = msg.charCodeAt(msg_len - 2) << 24 | msg.charCodeAt(msg_len - 1) << 16 | 0x08000;
                break;

            case 3:
                i = msg.charCodeAt(msg_len - 3) << 24 | msg.charCodeAt(msg_len - 2) << 16 | msg.charCodeAt(msg_len - 1) << 8 | 0x80;
                break;
        }

        word_array.push(i);

        while ((word_array.length % 16) != 14)
            word_array.push(0);

        word_array.push(msg_len >>> 29);
        word_array.push((msg_len << 3) & 0x0ffffffff);

        for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {

            for (i = 0; i < 16; i++)
                W[i] = word_array[blockstart + i];
            for (i = 16; i <= 79; i++)
                W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);

            A = H0;
            B = H1;
            C = H2;
            D = H3;
            E = H4;

            for (i = 0; i <= 19; i++) {
                temp = (rotate_left(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
                E = D;
                D = C;
                C = rotate_left(B, 30);
                B = A;
                A = temp;
            }

            for (i = 20; i <= 39; i++) {
                temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
                E = D;
                D = C;
                C = rotate_left(B, 30);
                B = A;
                A = temp;
            }

            for (i = 40; i <= 59; i++) {
                temp = (rotate_left(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
                E = D;
                D = C;
                C = rotate_left(B, 30);
                B = A;
                A = temp;
            }

            for (i = 60; i <= 79; i++) {
                temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
                E = D;
                D = C;
                C = rotate_left(B, 30);
                B = A;
                A = temp;
            }

            H0 = (H0 + A) & 0x0ffffffff;
            H1 = (H1 + B) & 0x0ffffffff;
            H2 = (H2 + C) & 0x0ffffffff;
            H3 = (H3 + D) & 0x0ffffffff;
            H4 = (H4 + E) & 0x0ffffffff;

        }

        var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

        return temp.toLowerCase();

    }

    /**
     * html5 的内部数据库
     */
    var Storage = function() {
        var uzStorage = function() {
            var ls = window.localStorage;
            if (IsAndroid()) {
                ls = os.localStorage();
            }
            return ls;
        };
        var set = function(key, value) {
            if (arguments.length === 2) {
                var v = value;
                if (typeof v == 'object') {
                    v = JSON.stringify(v);
                    v = 'obj-' + v;
                } else {
                    v = 'str-' + v;
                }
                var ls = uzStorage();
                if (ls) {
                    ls.setItem(key, v);
                }
            }
        };

        var get = function(key) {
            var ls = uzStorage();
            if (ls) {
                var v = ls.getItem(key);
                if (!v) { return; }
                if (v.indexOf('obj-') === 0) {
                    v = v.slice(4);
                    return JSON.parse(v);
                } else if (v.indexOf('str-') === 0) {
                    return v.slice(4);
                }
            }
        };
        var rm = function(key) {
            var ls = uzStorage();
            if (ls && key) {
                ls.removeItem(key);
            }
        };
        var clear = function() {
            var ls = uzStorage();
            if (ls) {
                ls.clear();
            }
        };

        return {
            get: get,
            set: set,
            rm: rm,
            clear: clear
        }

    }();

    var Screen = function(CB) {
        var WinWidth = $(window).width();
        var WinHeigh = $(window).height();

        var OnReSize = function(CB) {
            var ResizedWinWidth = $(window).width();
            var ResizedWinHeight = $(window).height();
            var scale_w = ResizedWinWidth / WinWidth;
            var scale_h = ResizedWinHeight / WinHeigh;
            var scale = scale_w >= scale_h ? scale_h : scale_w;
            if (CB) {
                CB(ResizedWinWidth, ResizedWinHeight, scale);
            }
            window.onresize = function() {
                OnReSize(CB);
            }
        }

        return {
            OnReSize: OnReSize
        }


    }();

    var md5 = function() {
        var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase        */
        var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance   */
        var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode      */
        /*
         * Perform a simple self-test to see if the VM is working
         */
        function md5_vm_test() {
            return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
        }

        /*
         * Calculate the MD5 of an array of little-endian words, and a bit length
         */
        function core_md5(x, len) {
            /* append padding */
            x[len >> 5] |= 0x80 << ((len) % 32);
            x[(((len + 64) >>> 9) << 4) + 14] = len;

            var a = 1732584193;
            var b = -271733879;
            var c = -1732584194;
            var d = 271733878;

            for (var i = 0; i < x.length; i += 16) {
                var olda = a;
                var oldb = b;
                var oldc = c;
                var oldd = d;

                a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
                d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
                c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
                b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
                a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
                d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
                c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
                b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
                a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
                d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
                c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
                b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
                a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
                d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
                c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
                b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);

                a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
                d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
                c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
                b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
                a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
                d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
                c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
                b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
                a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
                d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
                c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
                b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
                a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
                d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
                c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
                b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);

                a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
                d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
                c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
                b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
                a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
                d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
                c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
                b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
                a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
                d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
                c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
                b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
                a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
                d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
                c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
                b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);

                a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
                d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
                c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
                b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
                a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
                d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
                c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
                b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
                a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
                d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
                c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
                b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
                a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
                d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
                c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
                b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);

                a = safe_add(a, olda);
                b = safe_add(b, oldb);
                c = safe_add(c, oldc);
                d = safe_add(d, oldd);
            }
            return Array(a, b, c, d);

        }

        /*
         * These functions implement the four basic operations the algorithm uses.
         */
        function md5_cmn(q, a, b, x, s, t) {
            return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
        }

        function md5_ff(a, b, c, d, x, s, t) {
            return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
        }

        function md5_gg(a, b, c, d, x, s, t) {
            return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
        }

        function md5_hh(a, b, c, d, x, s, t) {
            return md5_cmn(b ^ c ^ d, a, b, x, s, t);
        }

        function md5_ii(a, b, c, d, x, s, t) {
            return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
        }

        /*
         * Calculate the HMAC-MD5, of a key and some data
         */
        function core_hmac_md5(key, data) {
            var bkey = str2binl(key);
            if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

            var ipad = Array(16),
                opad = Array(16);
            for (var i = 0; i < 16; i++) {
                ipad[i] = bkey[i] ^ 0x36363636;
                opad[i] = bkey[i] ^ 0x5C5C5C5C;
            }

            var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
            return core_md5(opad.concat(hash), 512 + 128);
        }

        /*
         * Add integers, wrapping at 2^32. This uses 16-bit operations internally
         * to work around bugs in some JS interpreters.
         */
        function safe_add(x, y) {
            var lsw = (x & 0xFFFF) + (y & 0xFFFF);
            var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
            return (msw << 16) | (lsw & 0xFFFF);
        }

        /*
         * Bitwise rotate a 32-bit number to the left.
         */
        function bit_rol(num, cnt) {
            return (num << cnt) | (num >>> (32 - cnt));
        }

        /*
         * Convert a string to an array of little-endian words
         * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
         */
        function str2binl(str) {
            var bin = Array();
            var mask = (1 << chrsz) - 1;
            for (var i = 0; i < str.length * chrsz; i += chrsz)
                bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
            return bin;
        }

        /*
         * Convert an array of little-endian words to a string
         */
        function binl2str(bin) {
            var str = "";
            var mask = (1 << chrsz) - 1;
            for (var i = 0; i < bin.length * 32; i += chrsz)
                str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
            return str;
        }

        /*
         * Convert an array of little-endian words to a hex string.
         */
        function binl2hex(binarray) {
            var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
            var str = "";
            for (var i = 0; i < binarray.length * 4; i++) {
                str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
                    hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
            }
            return str;
        }

        /*
         * Convert an array of little-endian words to a base-64 string
         */
        function binl2b64(binarray) {
            var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
            var str = "";
            for (var i = 0; i < binarray.length * 4; i += 3) {
                var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16) |
                    (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8) |
                    ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
                for (var j = 0; j < 4; j++) {
                    if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
                    else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
                }
            }
            return str;
        }

        var hex_md5 = function(s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }

        var b64_md5 = function(s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }

        var str_md5 = function(s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }

        var hex_hmac_md5 = function(key, data) { return binl2hex(core_hmac_md5(key, data)); }

        var b64_hmac_md5 = function(key, data) { return binl2b64(core_hmac_md5(key, data)); }

        var str_hmac_md5 = function(key, data) { return binl2str(core_hmac_md5(key, data)); }

        return {
            hex_md5: hex_md5,
            b64_md5: b64_md5,
            str_md5: str_md5,
            hex_hmac_md5: hex_hmac_md5,
            b64_hmac_md5: b64_hmac_md5,
            str_hmac_md5: str_hmac_md5
        }
    }();

    return {
        offset: offset,
        IsAndroid: IsAndroid,
        CheckVer: CheckVer,
        uuid: uuid,
        GetUrlParams: GetUrlParams,
        SHA1: SHA1,
        base64encode: base64encode,
        base64decode: base64decode,
        HtmlEncode: HtmlEncode,
        HtmlDecode: HtmlDecode,
        FixLen: FixLen,
        RemoveLoading: RemoveLoading,
        FillLoadingView: FillLoadingView,
        FillErrorView: FillErrorView,
        ShowNoData: ShowNoData,
        CheckEmail: CheckEmail,
        trim: trim,
        GetLen: GetLen,
        IsNum: IsNum,
        CheckStr: CheckStr,
        ForDight: ForDight,
        imageReady: imageReady,
        loadImage: loadImage,
        PreloadImages: PreloadImages,
        GetJsonDateStr: GetJsonDateStr,
        GetJsonDate: GetJsonDate,
        FormatDate: FormatDate,
        LoadScript: LoadScript,
        Storage: Storage,
        GetStakeNo: GetStakeNo,
        Screen: Screen,
        md5: md5,
        UrlEvent: UrlEvent

    }
}();

export default Tools;